package net.dgg.zz.credential.baseCredential.controller;

import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.zz.common.excption.CommonExcption;
import net.dgg.zz.credential.baseCredential.entity.BaseCredential;
import net.dgg.zz.credential.baseCredential.service.BaseCredentialService;
import net.dgg.zz.credential.excption.CertificateExcption;
import net.fblock.log.NLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 证书基础信息
 * create by 王茂婕 on 2018/8/13 0013
 */
@Controller
@RequestMapping("/zs/base_credential")
public class BaseCredentialController extends DggBaseController {

    @Resource
    private BaseCredentialService baseCredentialService;

    /**
     * 证书编号验重
     *
     * @param params
     * @return
     */
    @NLog()
    @RequestMapping("/check_credential_no")
    @ResponseBody
    public DggRestResponse checkCredentialNo(@RequestParam Map params) {
        try {
            // 根据指定条件查询证书编号
            BaseCredential baseCredential = baseCredentialService.checkCredentialNo(params);
            return this.getSuccessResponse(baseCredential);
        } catch (CertificateExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.getFailResponse(e.getMessage());
        }
    }

}
